import Vue from 'vue'
import app from './app.vue'
import axios from 'axios'
import VueRouter from 'vue-router'
import router from './router' // 引入外部路由文件
import Vuex from 'vuex' //导入公共数据管理插件
import 'element-ui/lib/theme-chalk/index.css'

import tinymce from 'tinymce'
import VueTinymce from '@packy-tang/vue-tinymce'

//样式
import 'tinymce/skins/content/default/content.min.css'
import 'tinymce/skins/ui/oxide/skin.min.css'
import 'tinymce/skins/ui/oxide/content.min.css'

//主题
import 'tinymce/themes/silver'

//插件
import 'tinymce/plugins/link' //链接插件
import 'tinymce/plugins/image' //图片插件
import 'tinymce/plugins/media' //媒体插件
import 'tinymce/plugins/table' //表格插件
import 'tinymce/plugins/lists' //列表插件
import 'tinymce/plugins/quickbars' //快速栏插件
import 'tinymce/plugins/fullscreen' //全屏插件

//本地化
import './utils/tinymce/langs/zh_CN.js'

Vue.prototype.$tinymce = tinymce
Vue.use(VueTinymce)

Vue.config.productionTip = false

// 启用导入模块******************
Vue.use(VueRouter)
Vue.use(Vuex)



// Elementui
import {
    Backtop,
    Button,
    Select,
    Drawer,
    Notification,
    Option,
    Input,
    Dialog,
    Form,
    FormItem,
    Switch
} from 'element-ui'
Vue.use(Backtop)
Vue.use(Button)
Vue.use(Select)
Vue.use(Drawer)
Vue.use(Option)
Vue.use(Input)
Vue.use(Dialog)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(Switch)
Vue.prototype.$notify = Notification;
// Vue.use(Message)



Vue.prototype.$ajax = axios; // 在组件中使用  this.$ajax.get("").then(res=>{}).catch(err=>{})
axios.defaults.baseURL = 'http://49.235.95.107/noteapi'; // 腾讯云服务器地址，开放8000端口
//http REQUEST 拦截器   -- 每次request都带token 在访问不需要认证的接口时401--目前在每个组件中单独使用token
axios.interceptors.request.use(config => {
    // Do something before request is sent
    let token = window.localStorage.getItem("token")
    if (token !== null) {
        config.headers.Authorization = `JWT ${token}`;
        return config;
    } else {
        return config;
    }


}, error => {
    // Do something with request error
    return Promise.reject(error);
});


Vue.filter("timeFormat", function (val) {
    if (val == "" || val == null) return ""
    let dd = new Date(val)
    let y = dd.getFullYear()
    let m = (dd.getMonth() + 1).toString().padStart(2, 0)
    let d = (dd.getDay()).toString().padStart(2, 0)
    return `${y}-${m}-${d}`
})

let store = new Vuex.Store({
    state: {
        forkList: []
    },
    mutations: {
        pushForkList(state, newlist) {
            this.state.forkList = newlist;
        }
    },
    getters: {
        getForkList(state) {
            return state.forkList;
        }
    }
})

// Vue实例
var vm = new Vue({
    el: "#app",
    render: c => c(app),
    router, //挂载抽离的路由文件--router.js
    store //挂载vuex实例--store状态管理对象
});